import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 				= $Lazy.file(()=>import('#private/cache-api'))
const $time 				= $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		// 搜索表单列表
		forms : [
			{ label: '条码号',		name: 'spec_code' },
			{ label: '科室',			name: 'department_name' },
			{ label: '岗位',			name: 'project_id',				type: 'select', loading:true },
			{ label: '项目',			name: 'kind_id',				type: 'select', loading:true },
			{ label: '状态',			name: 'status',					type: 'select', data:[{ name:'已审核', value: '45003' }, { name:'已批准', value: '45004' }] },
			{ label: '检测时间',		names: ['start_at','end_at'], 	name:'jz-time', type: 'date-range' },
			{ label: '接收时间',		names: ['ck_start_date','ck_end_date'],	name:'jz-time_1',		type: 'date-range' },
		],
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		// 设置时间默认值
		$time.then(f=>{
			const arr = f.duration['1-9-9']()
			this.resetModel = { start_at: arr[0], end_at: arr[1], 'jz-time':arr }
			this.model = $fn.copy(this.resetModel)
			if(window.isInit){
				this.fetch()
			}
		})
	}
	//获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 岗位
			$fn.setRow( forms, 'project_id', await f.getCache({ api:'gang_wei' } ) )
			// 项目
			$fn.setRow( forms, 'kind_id', await f.getCache({ api:'labkindselect' } ) )
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'specimen/laboratorylists')
	
	// 表单
	cols = [
		{ title: '条码号', 		dataIndex: 'spec_code', 			...$fn.table.spec_code },
		{ title: '实验号', 		dataIndex: 'experiment_num', 		width:150 },
		{ title: '送检单位', 	dataIndex: 'hosp_name', 			width:200 },
		{ title: '接收时间', 	dataIndex: 'receive_at', 			...$fn.table.time },
		{ title: '检测时间', 	dataIndex: 'created_at', 			...$fn.table.time },
		{ title: '姓名', 		dataIndex: 'patient_name', 			...$fn.table.name },
		{ title: '性别', 		dataIndex: 'sex_name', 				...$fn.table.sex },
		{ title: '年龄', 		dataIndex: 'age', 					...$fn.table.age },
		{ title: '证件类型', 	dataIndex: 'card_type_name', 		...$fn.table.card_type },
		{ title: '证件号', 		dataIndex: 'card_no', 				...$fn.table.idcard },
		{ title: '电话', 		dataIndex: 'patient_phone', 		...$fn.table.phone },
		{ title: '医生电话', 	dataIndex: 'doctor_phone', 			...$fn.table.phone },
		{ title: '科室', 		dataIndex: 'department_name', 		width:150 },
		{ title: '患者类型', 	dataIndex: 'case_type_name', 		width:150 },
		{ title: '床号', 		dataIndex: 'bed_no', 				...$fn.table.num },
		{ title: '住院号', 		dataIndex: 'outpatient', 			...$fn.table.num },
		{ title: '临床诊断', 	dataIndex: 'diagnosis_info', 		width:150 },
		{ title: '自然项目', 	dataIndex: 'parent_kind_name', 		width:150 },
		{ title: '检验项目', 	dataIndex: 'kind_name', 			width:150 },
		{ title: '批准时间', 	dataIndex: 'ts_approve_at', 		...$fn.table.time },
		{ title: '结果', 		dataIndex: 'result_str', 			width:150 },
		{ title: '状态', 		dataIndex: 'status_name', 			...$fn.table.status },
	]
	// 操作按钮
	controls = () => {
		return [
			Controls.exports.call(this, 'specimen/labkindexport'),			// 导出
		]
	}
	
	render(){
		return (
			<>
				<Page title='项目结果清单' controls={this.controls()}>
					{/* 搜索 */}
					{ SearchForm.call(this, { timeStr:'1-9-9' }) }
					{/* 表格 */}
					{ 
						Table.call(this,{isInit:window.isInit})
					}
				</Page>
			</>
		)
	}
}

export default Index